<?php
require('functions/page_load.php');

$content_nav = true;

if(isset($_GET['delete'])){

	$sql = "DELETE FROM faqs WHERE id = '".mysql_real_escape_string($_GET['delete'])."'";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	$results = '<div class="success_result">FAQ deleted successfully.</div>';

}

	$sql = "SELECT id, question, tradesman, user FROM faqs ORDER BY id DESC";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	$rows = mysql_num_rows($query);
	
	if($rows > 0){
	
	$content = '<table width="100%" cellpadding="0" cellspacing="0" class="cms_table"><thead><tr><th align="left">Question</th><th width="60">Tradesman</th><th width="60">User</th><th width="60">Edit</th><th width="50">Delete</th></tr></thead><tbody>';
	
		while($rs=mysql_fetch_assoc($query)){
		
		$tradesman = ($rs['tradesman'] == '1') ? '<img src="images/yes.png" alt="Yes" />' : '<img src="images/no.png" alt="No" />' ;
		$user = ($rs['user'] == '1') ? '<img src="images/yes.png" alt="Yes" />' : '<img src="images/no.png" alt="No" />' ;
		
		$content.='<tr><td align="left"><a href="edit_faq.php?id='.$rs['id'].'">'.$rs['question'].'</a></td><td valign="top">'.$tradesman.'</td><td valign="top">'.$user.'</td><td valign="top"><a href="edit_faq.php?id='.$rs['id'].'" title="Edit"><img src="images/edit.png" alt="edit" /></a></td><td><a onclick="confirm_delete(\'?delete='.$rs['id'].'\',\'this faq\');" title="Delete"><img src="images/delete.png" alt="Delete" /></a></td></tr>';
		
		}
		
	$content.='</tbody></table>';
		
	}
	
	else{
	
	$content = '<p style="float: left; width: 100%; text-align: center;">There are currently no FAQ\'s.</p>' ;
	
	}

require('includes/header.php');
?>

<div class="side_container">
<h2 class="container_header">Navigation</h2>

<ul>
<li><a href="content.php">Pages</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="directory.php">Directory</a></li>
<li><a href="faqs.php">FAQs</a></li>
</ul>

</div>

<div class="main_container_wrapper">

	<div class="main_container">
	<h2 class="container_header">FAQ's</h2>
	
	<a href="add_faq.php" class="create_button">Create new FAQ</a>
	
	<?php echo $results; ?>
	<?php echo $content; ?>

	</div>

</div>
	
<?php
	require('includes/footer.php');
?>